{extend name="common:frm_base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">{if $act eq 'add'}添加{else}编辑{/if}角色</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="{:url('Role/handle')}" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">角色名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="{$info['name']|default=''}" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="status" {if $info.status==1 }checked{/if} lay-skin="switch" value="1" lay-text="ON|OFF">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">权限资源</label>
                    <div class="layui-input-block">
                        <fieldset class="layui-elem-field">
                            <legend>选中所有</legend>
                            <div class="layui-field-box">
                                <input type="checkbox" title="所有" lay-filter="all_operation" value="0">
                            </div>
                        </fieldset>
                        {foreach $operation_list as $oKey=>$oVal}
                            <fieldset class="layui-elem-field">
                                <legend>{$oVal['name']}</legend>
                                <div class="layui-field-box"> <!--layui-nav-itemed-->
                                    <input type="checkbox" value="{$oVal['id']}" {if is_array($info['operation_arr']) && in_array($oVal['id'], $info['operation_arr'])} checked {/if} class="o_check" name="operation_id[]" title="{$oVal['name']}">
                                    {if $oVal['child'] }
                                        {foreach $oVal['child'] as $childKey=>$childVal}
                                        <fieldset class="layui-elem-field">
                                            <legend>{$childVal['name']}</legend>
                                            <div class="layui-field-box"> <!--layui-nav-itemed-->
                                                <input type="checkbox" value="{$childVal['id']}" {if is_array($info['operation_arr']) && in_array($childVal['id'], $info['operation_arr'])} checked {/if} class="o_check" name="operation_id[]" title="{$childVal['name']}">
                                                {foreach $childVal['child'] as $itemKey=>$itemVal}
                                                    <input type="checkbox" value="{$itemVal['id']}" {if is_array($info['operation_arr']) && in_array($itemVal['id'], $info['operation_arr'])} checked {/if} class="o_check" name="operation_id[]" title="{$itemVal['name']}">
                                                {/foreach}
                                            </div>
                                        </fieldset>
                                        {/foreach}
                                    {/if}
                                </div>
                            </fieldset>
                        {/foreach}
                    </div>
                </div>
                {:token()}
                <input type="hidden" value="{$act}" name="act" />
                <input type="hidden" value="{$info['id']|default=''}" name="id" />
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
                </div>
                <!--<div class="layui-form-item layui-layout-admin">-->
                <!--<div class="layui-input-block">-->
                <!--<div class="layui-footer" style="left: 0;">-->
                <!--<button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>-->
                <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
            </form>
        </div>
    </div>
</div>


<script>
    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });

        form.on('checkbox(all_operation)', function (data) {
            var is_check = data.elem.checked;
            var value = data.value;
            if (is_check && value == 0) {
                //全选
                $(".o_check").prop('checked', true);
                form.render('checkbox');
            } else if (!is_check && value == 0) {
                //取消全选
                $(".o_check").prop('checked', false);
                form.render('checkbox');
            }
        });


    });
</script>
{/block}